class Solution(object):
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if strs == [] or strs == [""]:
            return ""

        if len(strs) == 1:
            return strs[0]

        prefix = ""
        i = 0
        while True:
            if i >= len(strs[0]):
                return prefix
            c = strs[0][i]
            for s in strs:
                if i >= len(s):
                    return prefix
                if s[i] != c:
                    return prefix
            prefix += c
            i += 1


s = Solution()
cases = [
    [],
    [""],
    ["a"],
    ["a", "a"],
    ["abc", "ab", "abcd"]
]
for case in cases:
    r = s.longestCommonPrefix(case)
    print(r)

